Ext.define('BM.controller.TokenBrowsers', {
    extend: 'Ext.app.Controller',
	views:  ['main.TokenBrowser'],
	stores: ['Tokens'],
	models: ['Token'],
    init: function() {
    
         this.control({
            'tokenbrowser': {
                itemdblclick: this.fireTokenSelected,
                selectionchange:this.onTokenSelect,
                itemcontextmenu:this.onTokenContextMenu
            },
            'tokencontextmenu':{
                click: this.onTokenContextMenuClick
            }
        });
    },
       //双击选择指定的手牌
    fireTokenSelected: function(view,record,item,index,e) {
     	
        var _tokenOrder = Ext.widget('tokenorder');
    	    _tokenOrder.show();
    },
     //单击选中指定的手牌
    onTokenSelect: function(dataview, selections) {
    	
    	//this.onShowOrderInfo();
    	
      	var selected = selections[0];
        if (selected) {
           // alert(selected.get("handTokenNum"));
        }
    },
      //单击手牌鼠标右键时的菜单
    onTokenContextMenu:function(view,record,item,index,e){
    
    	e.stopEvent();
        var _menu = Ext.widget('tokencontextmenu');
        _menu.showAt(e.getXY());
        return false;
    },
     //单击手牌右键菜单的一个选项时
    onTokenContextMenuClick:function(menu,item,e){
    
    	if(item.name == 'COST_ORDER'){
    		var _tokenOrder = Ext.widget('tokenorder');
    	    _tokenOrder.show();
    	}else if(item.name == 'COST_ADD'){
    	
    		var _costItem = Ext.widget('addcostitem');
    		_costItem.show();
    	}else if(item.name == 'COST_CHECKOUT'){
    	
    		var _checkOut = Ext.widget('tokencheckout');
    		_checkOut.show();
    	}else if(item.name == 'TOKEN_BOOK'){
    	
    		var _customerBook = Ext.widget('customerbook');
    		_customerBook.show();
    	}else if(item.name == 'TOKEN_CHANGE'){
    	
    		var _changeToke = Ext.widget('changetoken');
    		_changeToke.show();
    	}else if(item.name == 'COST_ADDDOWNPAY'){
    	
    		var _addDownPay = Ext.widget('adddownpay');
    		_addDownPay.show();
    	}
    }
});